﻿using System;
using System.IO;

namespace Coding4Fun.BoxingBots.Common
{
	public struct CalculatedSensorData
	{
		public double TopRight { get; set; }
		public double TopLeft { get; set; }
		public double BottomRight { get; set; }
		public double BottomLeft { get; set; }

		public bool IsRightSwitchTriggered { get; set; }
		public bool IsLeftSwitchTriggered { get; set; }

		public bool IsSwitchTriggered
		{
			get { return IsRightSwitchTriggered && IsLeftSwitchTriggered; }
		}

		public CalculatedSensorData Read(BinaryReader br)
		{
			TopLeft = br.ReadDouble();
			TopRight = br.ReadDouble();
			BottomLeft = br.ReadDouble();
			BottomRight = br.ReadDouble();
			IsLeftSwitchTriggered = br.ReadBoolean();
			IsRightSwitchTriggered = br.ReadBoolean();
			return this;
		}

		public void Write(BinaryWriter bw)
		{
			bw.Write(TopLeft);
			bw.Write(TopRight);
			bw.Write(BottomLeft);
			bw.Write(BottomRight);
			bw.Write(IsLeftSwitchTriggered);
			bw.Write(IsRightSwitchTriggered);
		}

		public override string ToString()
		{
			return string.Format(
								"TopLeft: {0}" + Environment.NewLine +
								"TopRight: {1}" + Environment.NewLine +
								"BottomLeft: {2}" + Environment.NewLine +
								"BottomRight: {3}" + Environment.NewLine +
								"IsLeftSwitchTriggered: {4}" + Environment.NewLine +
								"IsRightSwitchTriggered: {5}" + Environment.NewLine,
								TopLeft, TopRight, BottomLeft, BottomRight, IsLeftSwitchTriggered, IsRightSwitchTriggered);
		}
	}
}
